var app = getApp()

Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    studentList: [{
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "/assets/home.png",
        "selectedIconPath": "/assets/home_selected.png"
      },
      {
        "pagePath": "/pages/course/course",
        "text": "课程",
        "iconPath": "/assets/course.png",
        "selectedIconPath": "/assets/course_selected.png"
      },
      {
        "pagePath": "/pages/me/me",
        "text": "我的",
        "iconPath": "/assets/me.png",
        "selectedIconPath": "/assets/me_selected.png"
      }
    ],
    teacherList: [{
        "pagePath": "/pages/teacher/teacher",
        "text": "老师",
        "iconPath": "/assets/home.png",
        "selectedIconPath": "/assets/home_selected.png"
      },
      // {
      //   "pagePath": "/pages/course/course",
      //   "text": "课程",
      //   "iconPath": "/assets/course.png",
      //   "selectedIconPath": "/assets/course_selected.png"
      // },
      // {
      //   "pagePath": "/pages/me/me",
      //   "text": "我的",
      //   "iconPath": "/assets/me.png",
      //   "selectedIconPath": "/assets/me_selected.png"
      // },
    ],
    bossList: [{
        "pagePath": "/pages/boss/boss",
        "text": "首页",
        "iconPath": "/assets/home.png",
        "selectedIconPath": "/assets/home_selected.png"
      },
      // {
      //   "pagePath": "/pages/course/course",
      //   "text": "课程",
      //   "iconPath": "/assets/course.png",
      //   "selectedIconPath": "/assets/course_selected.png"
      // },
      // {
      //   "pagePath": "/pages/me/me",
      //   "text": "我的",
      //   "iconPath": "/assets/me.png",
      //   "selectedIconPath": "/assets/me_selected.png"
      // },
    ],
    educationalList: [{
        "pagePath": "/pages/teacherLead/teacherLead",
        "text": "首页",
        "iconPath": "/assets/home.png",
        "selectedIconPath": "/assets/home_selected.png"
      },
      // {
      //   "pagePath": "/pages/course/course",
      //   "text": "课程",
      //   "iconPath": "/assets/course.png",
      //   "selectedIconPath": "/assets/course_selected.png"
      // },
      // {
      //   "pagePath": "/pages/me/me",
      //   "text": "我的",
      //   "iconPath": "/assets/me.png",
      //   "selectedIconPath": "/assets/me_selected.png"
      // }
    ],
    selectList: [],
  },
  attached() {
    let selectList
    if (!wx.getStorageSync('environment')) {
      selectList = this.data.studentList
      this.setData({
        selectList: selectList,
      })
    }
    this.rolesTest(selectList)
  },
  methods: {
    rolesTest(selectList) {
      // 角色检测
      if (app.globalData.userInfo) {
        let role = app.globalData.userInfo.roles[0]
        console.log(role)
        if (role == 'boss') {
          selectList = this.data.bossList
        } else if (role == 'educational') {
          selectList = this.data.educationalList
        } else if (role == 'teacher') {
          selectList = this.data.teacherList
        } else {
          selectList = this.data.studentList
        }
        this.setData({
          selectList: selectList,
        })
      } else {
        setTimeout(() => {
          this.rolesTest(selectList)
        }, 100)
      }
    },
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      // console.log(data)
      wx.switchTab({
        url
      })
      this.setData({
        selected: data.index
      })
    }
  }
})